package com.yeyks.appcontroller;

import com.yeyks.base.Arguments;
import com.yeyks.dto.AppInfoDTO;
import com.yeyks.exception.ServiceException;
import com.yeyks.model.Ajax.AjaxResponseBody;
import com.yeyks.service.AppInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author fuchangshuai
 * @date 2019/3/26 4:27 PM
 */
@Api(tags = "版本信息", description = "版本")
@Slf4j
@RestController
@RequestMapping(value = "/app")
public class AppInfoController {

    @Autowired
    private AppInfoService appInfoService;
    /**
     * 获取版本信息
     *
     * @return
     */
    @ApiOperation(value = "获取版本信息", notes = "获取版本信息", response = AppInfoDTO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "version", value = "version", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "type", value = "类型(iOS,Android)", required = true, dataType = "String")
    })
    @RequestMapping(value = "/system/version", method = RequestMethod.POST)
    public ResponseEntity<?> systemVersion(@RequestParam(value = "version") String version,
                                           @RequestParam(value = "type") String type) {
        if (!Arguments.notEmpty(version)) {
            throw new ServiceException("版本号不能为空");
        }
        AppInfoDTO appInfoDTO = appInfoService.getAppInfoByType(type, version);
        return ResponseEntity.ok(AjaxResponseBody.success(appInfoDTO));
    }
}
